<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
$page = is_numeric($_GET['page']) ? $_GET['page'] : 1;
$PageCount = 20;

$aURL = "CommentManage.php?page={$page}&Lang={$Lang}&Type={$_GET['Type']}&Cid={$_GET['Cid']}";
switch ($_GET['a']){
	case 'y': //通过审核
		if($db->ExecuteSQL("UPDATE `{$dbprefix}comment` SET `CommentAudit` = '1' WHERE `ID` = '{$_GET['ID']}' LIMIT 1;")){
			AdminLog(1,$Lang,"通过评论审核(ID:{$_GET['ID']})，结果：操作成功！"); 
			MsgBox (0,'',$aURL);		
		}else{
			AdminLog(1,$Lang,"通过评论审核(ID:{$_GET['ID']})，结果：操作失败！"); 
			MsgBox (1,'操作失败！','-1');	
		}
		break;	
	case 'n': //取消审核
		if($db->ExecuteSQL("UPDATE `{$dbprefix}comment` SET `CommentAudit` = '0' WHERE `ID` = '{$_GET['ID']}' LIMIT 1;")){
			AdminLog(1,$Lang,'取消评论审核(ID:' . $_GET['ID'] . ')，结果：操作成功！'); 
			MsgBox (0,'',$aURL);		
		}else{
			AdminLog(1,$Lang,'取消评论审核(ID:' . $_GET['ID'] . ')，结果：操作失败！'); 
			MsgBox (1,'操作失败！','-1');	
		}
		break;
	case 'd': //删除
		if($db->ExecuteSQL("DELETE FROM `{$dbprefix}comment` WHERE `ID` = '{$_GET['ID']}' LIMIT 1;")){
			AdminLog(3,$Lang,'删除评论(ID:' . $_GET['ID'] . ')，结果：删除成功！'); 
			MsgBox (0,'',$aURL);		
		}else{
			AdminLog(3,$Lang,'删除评论(ID:' . $_GET['ID'] . ')，结果：删除失败！'); 
			MsgBox (1,'删除失败！','-1');	
		}
		break;	
}
if($_POST['a'] == 'BulkDel'){ //批量删除
	$AllDel = $_POST['AllDel'];
	$AllDel != '' ? $AllDel = array_merge(array_diff($AllDel,$NotDelProduct)) : MsgBox (1,'操作失败，请选择要删除的评论！','-1'); //从选择的文章ID中移去配置文件中禁止删除的文章内容ID
	$AllDel = implode(',',$AllDel); //Array转成字串
	if($db->ExecuteSQL("DELETE FROM `{$dbprefix}comment` WHERE `ID` IN (" . $AllDel . ")")){
		AdminLog(3,$Lang,'批量删除评论(ID:' . $AllDel . ')，结果：操作成功！'); 
		MsgBox (1,'操作成功！',$aURL);		
	} else {
		AdminLog(3,$Lang,'批量删除评论，结果：操作失败！'); 
		MsgBox (1,'操作失败！','-1');		
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script type="text/javascript"> 
function CheckAll(form) { //复选框全选/取消
	for (var i=0;i<form.elements.length;i++) { 
		var e = form.elements[i]; 
		if (e.Name != "chkAll"&&e.disabled!=true) 
		e.checked = form.chkAll.checked; 
	} 
} 
</script>
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd"><td><?php TopLang();?></td>
	<td align="right">
		<input type="button" value="刷新数据" onClick="javascript:location.href='CommentManage.php?Lang=<?php echo $Lang?>'">
		<select OnChange="window.open(this.options[this.selectedIndex].value,'_self')" size="1">
		<option value="CommentManage.php?Lang=<?php echo $Lang;?>">==全部评论==</option>
		<option value="CommentManage.php?Lang=<?php echo $Lang;?>&Type=0" <?php if($_GET['Type'] == '0') echo 'selected="selected"';?>>内容评论</option>
		<option value="CommentManage.php?Lang=<?php echo $Lang;?>&Type=1" <?php if($_GET['Type'] == '1') echo 'selected="selected"';?>>产品评论</option>
		<option value="CommentManage.php?Lang=<?php echo $Lang;?>&Type=2" <?php if($_GET['Type'] == '2') echo 'selected="selected"';?>>新闻评论</option>
		<option value="CommentManage.php?Lang=<?php echo $Lang;?>&Type=3" <?php if($_GET['Type'] == '3') echo 'selected="selected"';?>>调查评论</option>
		</select>	
	</td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form id="form1" name="form1" method="post" action="CommentManage.php?page=<?php echo $page?>&Type=<?php echo $_GET['Type']?>&Cid=<?php echo $_GET['Cid'];?>&Lang=<?php echo $Lang?>">
  <tr>
    <td colspan="4" align="center" class="Main_Title">评论管理<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td height="20" align="center" width="60"><input name="chkAll" type="checkbox" id="chkAll" onclick="CheckAll(this.form)" value="checkbox"></td>
    <td align="center"><strong>标题</strong></td>
    <td align="center"><strong>评论内容</strong></td>
    <td align="center"><strong>管理选项</strong><br /><font color="#ABABAB">审核 | 删除 | 预览</font></td>
  </tr>
<?php
$SQL = "SELECT * FROM `{$dbprefix}comment` WHERE `CommentLang` = $Lang ";
if($_GET['ProductRela'] != ''){$SQL .= "&& `ProductRela` LIKE '" . $_GET['ProductRela'] . "%' ";}
if(is_numeric($_GET['Type'])) $SQL .= "&& `CommentType` = '{$_GET['Type']}' ";
if(is_numeric($_GET['Cid'])) $SQL .= "&& `CommentID` = '{$_GET['Cid']}' "; //相关id
$RsCount = count($db->SelectSQL($SQL)); //总记录数
$SQL .= "ORDER BY `ID` DESC "; 
$SQL .= "LIMIT " . ($page-1)*$PageCount . " , " . $PageCount . " ";
//die($SQL);
$RsArray = $db->SelectSQL($SQL,1);
foreach ($RsArray as $i => &$n){
	//获取评论标题
	switch ($n['CommentType']){
		case '0' : $tname = "{$dbprefix}article"; $fname = 'ArticleTitle'; $ct = '[内容]';	break;
		case '1' : $tname = "{$dbprefix}product"; $fname = 'ProductName'; $ct = '[产品]';	break;
		case '2' : $tname = "{$dbprefix}news"; $fname = 'NewsTitle'; $ct = '[新闻]';	break;
		case '3' : $tname = "{$dbprefix}survey"; $fname = 'SurveyTitle'; $ct = '[调查]';	break;
		default: $ct = 'NULL'; break;
	}	
	$SQL = "SELECT `{$fname}` FROM `{$tname}` WHERE `ID` = '{$n['CommentID']}' LIMIT 0,1";
	if($Title = $db->SelectSQL($SQL,0)){
		$Title = "{$ct} <a title=\"只显示该内容的相关评论\" href=\"CommentManage.php?Lang={$Lang}&Type={$n['CommentType']}&Cid={$n['CommentID']}\">{$Title[0][0]}</a>";
	} else {
		$Title = '<em>NULL</em>';
	}
	$n['CommentContent'] = nl2br(htmlspecialchars($n['CommentContent']));
	$aURL .= "&ID={$n['ID']}&a=";
	$mg = $n['CommentAudit']==1 ? "<a href=\"{$aURL}n\">取消</a> | " : "<a href=\"{$aURL}y\"><font color=\"#FF0000\">通过</font></a> | ";
	$mg .= "<a onClick=\"return confirm('确定要删除该评论吗？');\" href=\"{$aURL}d\">删除</a> | ";
	$mg .= "<a target=\"_blank\" href=\"../?fcomment/l{$n['CommentLang']}/t{$n['CommentType']}/i{$n['CommentID']}\">查看</a>";
	echo "<tr class=\"odd\">
	<td height=\"20\" align=\"center\"><input name=\"AllDel[]\" type=\"checkbox\" value=\"{$n['ID']}\" /></td>
	<td>{$Title}</td>
	<td width=\"40%\">{$n['CommentContent']}</td>
	<td align=\"center\">{$mg}</td>
	</tr>";
}
?>  
  <tr class="odd">
  	<td align="center">
		<input type="hidden" name="a" value="BulkDel" />
		<input type="submit" name="button" id="button" value="删除" onClick="return confirm('确定要删除所有选定的评论吗？');" />
	</td>
    <td height="35" align="center" colspan="3">
		<?php if($RsCount>0) {echo pages("Lang={$Lang}&Type={$_GET['Type']}&Cid={$_GET['Cid']}");} else {echo '没有相关数据！';}?>
	</td>
  </tr>
  </form>
</table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;"></td>
	</tr>
</table>  
</body>
</html>
